package com.qf.day08.user;

import java.util.Scanner;

public class Menu {

    // 声明一个接口PrintBanner类型的属性
    private PrintBanner printBanner;

    public PrintBanner getPrintBanner() {
        return printBanner;
    }

    public void setPrintBanner(PrintBanner printBanner) {
        this.printBanner = printBanner;
    }

    public void show(){

        // 打印 程序的 banner
        printBanner.print();

        //1. 创建局部变量
        UserService userService = new UserServiceImpl();
        while (true){
            System.out.println("请选择功能：1.注册 \t 2.登录 \t 3. 退出");
            Scanner scanner = new Scanner(System.in);
            String menuItem = scanner.next();
            switch (menuItem){
                case "1":
                    System.out.println("请输入注册的用户名:");
                    String username = scanner.next();
                    System.out.println("请输入注册的密码:");
                    String password = scanner.next();
                    boolean flag = userService.regist(username, password);
                    if (flag){
                        System.out.println("恭喜，注册成功啦");
                    }else {
                        System.out.println("很遗憾，注册失败");
                    }
                    break;
                case "2":
                    System.out.println("请输入的用户名:");
                    String loginName = scanner.next();
                    System.out.println("请输入注册的密码:");
                    String loginPassword = scanner.next();
                    boolean loginFlag = userService.login(loginName, loginPassword);
                    if (loginFlag){
                        System.out.println("恭喜，登录成功啦");
                    }else {
                        System.out.println("很遗憾，登录失败");
                    }
                    break;
                case "3":
                    System.out.println("886");
                    return;
                default:
                    System.out.println("输入错误");

            }
        }




    }

}
